

function switchVisibility(blockId) {
    var block = document.getElementById(blockId);
    if (!block.style.display || block.style.display == "" || block.style.display == "block") {
        block.style.setAttribute("display", "none");
    } else {
        block.style.setAttribute("display", "block");
    }
}
function disableField(fieldName) {
    var f = document.getElementsByName(fieldName)[0];
    if (f != null && f.value == "") {
        f.disabled = true;
    }
}
function openFullSizeWindow(uri, windowName) {
    return openWindow(uri, windowName, screen.width, screen.height);
}
function openWindow(uri, windowName, winWidth, winHeight) {
    if (winWidth == null) {
        winWidth = screen.width;
    }
    if (winHeight == null) {
        winHeight = screen.height;
    }
    var winLeft = (screen.width - winWidth) / 2;
    var winTop = (screen.height - winHeight) / 2;
    var styleString = "top=" + winTop + ",left=" + winLeft + ",toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=" + winWidth + ",height=" + winHeight;
    var newWindow = window.open(uri, windowName, styleString);
}

function openWindowRtn(uri, windowName) {
    
    var winWidth = screen.width; 
    var winHeight = screen.height;
    var winLeft = (screen.width - winWidth) / 2;
    var winTop = (screen.height - winHeight) / 2;
    var styleString = "top=" + winTop + ",left=" + winLeft + ",toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=" + winWidth + ",height=" + winHeight;
    return window.open(uri, windowName, styleString); 
}
function openNewWindow(uri, windowName, winWidth, winHeight) {
    if (winWidth == null) {
        winWidth = screen.width;
    }
    if (winHeight == null) {
        winHeight = screen.height;
    }
    var winLeft = (screen.width - winWidth) / 2;
    var winTop = (screen.height - winHeight) / 2;
    var styleString = "top=" + winTop + ",left=" + winLeft + ",toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=" + winWidth + ",height=" + winHeight;
    var newWindow = window.open(uri, windowName, styleString);
    newWindow.focus();
}
function selectOrg(orgId, orgName) {
    var url = "goto.sysmgr.org.SubOrgOption.do?orgId=" + orgId + "&orgName=" + orgName;
    var newWindow = openWindow(url, "SelectOrg", 450, 400);
    //newWindow.focus();
    //return newWindow;
}

function selectOrgToCode(orgId, orgName) {
    var url = "goto.sysmgr.org.SubOrgOptionToCode.do?orgId=" + orgId + "&orgName=" + orgName;
    var newWindow = openWindow(url, "SelectOrg", 450, 400);
    //newWindow.focus();
    //return newWindow;
}

function amortizationSetup(writeOffInstanceId, canEdit) {
    var url = "amortize.setup.do?actionMode=viewFromWriteOff&id=" + writeOffInstanceId;
    if (canEdit && canEdit == "true") {
        url = "amortize.setup.do?id=" + writeOffInstanceId;
    }
    newWindow = openWindow(url, "Amortize", 800, 480);
    //newWindow.focus();
    //return newWindow;
}
function viewCertificate(id) {
    var url = "certificate.updateCertificate.do?actionType=readOnly&id=" + id;
    newWindow = openFullSizeWindow(url, "viewCertificate");
    //newWindow.focus();
    //return newWindow;
}
function selectCostCenter(costCenterCode, costCenterName) {
    var url = "goto.sysmgr.org.SapCostCenterOption.do?costCenterCode=" + costCenterCode + "&costCenterName=" + costCenterName;
    var newWindow = openWindow(url, "selectCostCenter", 450, 400);
    //newWindow.focus();
    //return newWindow;
}

//????????????????????????????????????????????????????????????????????????????????
function disableInvalidField(inputName, invalidValue) {
    if (document.getElementsByName(inputName)[0].value == invalidValue) {
        document.getElementsByName(inputName)[0].disabled = true;
    } else {
        document.getElementsByName(inputName)[0].disabled = false;
    }
}

//--????????????-begin
var originalBgColor;
var originalClBgColor;
var loR;
var newColor = "#4da1ec";//onmouseover
//var newColor = "#DFEFF8";
var clickColor = "#f8a5a5";//click
function activateRolloverEffectTable(tbl, rolloverColor) {
    newColor = (rolloverColor == null) ? newColor : rolloverColor;
    for (i = 1; i < tbl.rows.length; i++) {
        addMouseOverListenerToRow(tbl.rows[i], changeBgColor(tbl.rows[i]));
        addMouseOutListenerToRow(tbl.rows[i], resumeBgColor(tbl.rows[i]));
    }
}
function changeBgColor(r) {
	if(r.className!='LastItem'){
    originalBgColor = r.cells[0].currentStyle.backgroundColor;
    for (i=0; i<r.cells.length; i++) {
        r.cells[i].style.backgroundColor = newColor;
    }
  }
}
function resumeBgColor(r) {
	if(r.className!='LastItem'){
    for (i=0; i<r.cells.length; i++) {
        r.cells[i].style.backgroundColor = originalBgColor;
    }
  }    
}
function clickBgColor(r) { 
	if(loR!=null){
		for (i=0; i<loR.cells.length; i++) {
        loR.cells[i].style.backgroundColor = originalClBgColor;
    }  
  }
    originalClBgColor = r.cells[0].currentStyle.backgroundColor;
    for (i=0; i<r.cells.length; i++) {
        r.cells[i].style.backgroundColor = clickColor;
    }
	loR=r;
}
function addMouseOverListenerToRow(r, listener) {
    var appName = window.navigator.appName;
    if (appName == "Microsoft Internet Explorer") {
        r.attachEvent("onmouseover", listener);
    } else {
        if (appName == "Netscape") {
            r.addEventListener("mouseover", listener);
        }
    }
}
function addMouseOutListenerToRow(r, listener) {
    var appName = window.navigator.appName;
    if (appName == "Microsoft Internet Explorer") {
        r.attachEvent("onmouseout", listener);
    } else {
        if (appName == "Netscape") {
            r.addEventListener("mouseout", listener);
        }
    }
}
function budgetGroupSelect(budgetInstanceCode,budgetItemGroupFrom) {
	
    var url = "budget.BudgetGroupCompiledListWriteOff.do?action=loadArchives&budgetInstanceCode=" + budgetInstanceCode+"&budgetItemGroupFrom="+document.all("vo.budgetItemGroupFrom").value;
   	
    newWindow = openFullSizeWindow(url, "BudgetGroupSelect");
     //openWindow(url, "BudgetGroupSelect", 700,500 ); 
}

function budgetGroupSelect(budgetInstanceCode) {
    var url="budget.BudgetGroupCompiledListWriteOff.do?action=loadArchives&budgetInstanceCode="+budgetInstanceCode;  
     newWindow=openFullSizeWindow(url, "BudgetGroupSelect");
     //openWindow(url, "BudgetGroupSelect", 700,500 ); 
}

function budgetGroupSelectForSixForm(orgId,budSetId,num) {
	
    var url = "budget.BudgetGroupCompiledListWriteOff.do?action=loadSixFeeArchives&orgId=" + orgId+"&budSetId="+budSetId+"&num="+num;   	
   // newWindow = openFullSizeWindow(url, "BudgetGroupSelect");
     openWindow(url, "BudgetGroupSelect", 700,500 ); 
}
//获取元素的纵坐标
function getTop(e) {
    var offset = e.offsetTop;
    if (e.offsetParent != null) {
        offset += getTop(e.offsetParent);
    }
    return offset;
}
//获取元素的横坐标
function getLeft(e) {
    var offset = e.offsetLeft;
    if (e.offsetParent != null) {
        offset += getLeft(e.offsetParent);
    }
    return offset;
}
//设置下拉框位置
function setLeftTop(iFrameDiv,inputBox){
	if(iFrameDiv&&inputBox){
		iFrameDiv.style.left=getLeft(inputBox)+"px";
		iFrameDiv.style.top=getTop(inputBox)+inputBox.offsetHeight-1+"px";		
	}
}

//合同列账选择报账单类型时设置下拉框位置,在右上角位置yangcheng09-06-23
function setLeftTopOnlyforContract(iFrameDiv,inputBox){
	if(iFrameDiv&&inputBox){		
		iFrameDiv.style.left=getLeft(inputBox)+inputBox.offsetWidth-5+"px";
		iFrameDiv.style.top=getTop(inputBox)+"px";		
	}
}


function setRight(iFrameDiv,inputBox){
	if(iFrameDiv&&inputBox){
		iFrameDiv.style.left=getLeft(inputBox)+inputBox.offsetWidth-5+"px";
		iFrameDiv.style.top=getTop(inputBox)-1+"px";		
	}
}
//--????????????-end

function selectStatus() {
    var url = "goto.writeoff.writeoffquery.WriteoffStatus.do?";   
    var newWindow = openWindow(url, "selectStatus", 350, 300);
    
}
function selectFinanceStatus() {
    var url = "goto.finance.FinanceInsStatus.do?";   
    var newWindow =openWindow(url, "selectStatus", 350, 300);
    
}
/*打印去除页尾页脚。(物资打印)*/
var hkey_root,hkey_path,hkey_key
hkey_root="HKEY_CURRENT_USER"
hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"
//设置网页打印的页眉页脚为空
function pagesetup_null()
{ 
  try{
    try   
    {   
      new  ActiveXObject("Wscript.Shell");   
    }   
    catch(e)   
    {   
          alert("当前IE安全级别不允许操作！");   
    }
    var RegWsh = new ActiveXObject("WScript.Shell")
    hkey_key="header"    
    RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
    hkey_key="footer"
    RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
  }catch(e){ }
}

//设置网页打印的页眉页脚为默认值(这里暂时没有用到。)
function pagesetup_default()
{
  try{
    var RegWsh = new ActiveXObject("WScript.Shell")
    hkey_key="header"    
    RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b??????&p/&P")
    hkey_key="footer"
    RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&u&b&d")
  }catch(e){}
}

function viewBarcodeAttachmentQuantity(instanceCode){
     URL="viewBarCodeAttachmentQuantity.do?instanceCode="+instanceCode;
	 sendRequest(URL); 
}

function showBarcodeAttachmentQuantity(quantity,instanceCode){
   var obj =document.getElementById(instanceCode);
   /*var split_="(";
   if(obj){
      ainnerHTML=obj.innerHTML;
      if(ainnerHTML.indexOf(split_)<0){
        obj.innerHTML=ainnerHTML+split_+quantity+")";
      }else{
         obj.innerHTML=ainnerHTML.substring(0,obj.innerHTML.indexOf(split_))+split_+quantity+")";
      }
   }*/
   if(obj){
      obj.innerHTML=quantity;
   }
}

function hotTel(){
var url = "goto.HotTel.do?";
 openWindow(url, "????????", 460,280 )
}


function openWindowForSixFee(uri, windowName) {   
    var winWidth = screen.width;   
    var winHeight = screen.height;  
    var winLeft = (screen.width - winWidth) / 2;
    var winTop = (screen.height - winHeight) / 2;
    var styleString = "top=" + winTop + ",left=" + winLeft + ",toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,width=" + winWidth + ",height=" + winHeight;
    var newWindow = window.open(uri, windowName, styleString);
}
function setPrintBase(headerText,footerText,rootUrl) {  
 
   // -- advanced features  ，未曾使用过，有待确认。  
	   
	        //factory.printing.SetMarginMeasure(2); // measure margins in inches  
 
	         //factory.SetPageRange(false, 1, 3);// need pages from 1 to 3  
	   
	           //factory.printing.printer = "HP DeskJet 870C";  
	  
	        //factory.printing.copies = 2;  
	  
	          //factory.printing.collate = true;  
	   
	         //factory.printing.paperSize = "A4";  
	     
	         //factory.printing.paperSource = "Manual feed"  
	   
	       var header = (headerText==null||headerText=="")?'默认页眉':headerText;  
	   
	     var footer = (footerText==null||footerText=="")?'默认页角':footerText;  
	    
	     factory.printing.header = "&b"+header+"&b" ;  
	     
	     factory.printing.footer = "&b"+footer;  
	     
	    factory.printing.portrait = true;  
	     
	    factory.printing.leftMargin =10.00;  
	   
	     factory.printing.topMargin =10.00;  
	     
	     factory.printing.rightMargin =10.00;  
	     
	     factory.printing.bottomMargin =10.00;  
	     
	  }  
